package com.example.jiwhsgs;

import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import java.util.HashMap;

public class cal_sp extends AppCompatActivity {

    private HashMap<Integer, Boolean> buttonStates;
    private Button button_cz;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 隐藏状态栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.cal_sp);
        // 初始化按钮状态
        buttonStates = new HashMap<>();
        initializeButtonStates();
        button_cz = findViewById(R.id.chongZhi);
        button_cz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initializeButtonStates();
                for (int id : buttonStates.keySet()) {
                    View button = findViewById(id);
                    if (button != null) {
                        button.setBackgroundResource(R.drawable.sliver_button);
                    }
                }
            }
        });
    }

    private void initializeButtonStates() {
        int[] buttonIds = {
                R.id.kill,
                R.id.fireKill,
                R.id.wuxiekeji,
                R.id.jiedaoshashen,
                R.id.leisha,
                R.id.guohechaqiao,
                R.id.shunshouqianyang,
                R.id.wuzhongshengyou,
                R.id.shan,
                R.id.wuguFengdeng,
                R.id.taoyuanjieyi,
                R.id.tieSuolianHuan,
                R.id.jiu,
                R.id.wanJianQifafa,
                R.id.juedu,
                R.id.nanManShuRu,
                R.id.tao,
                R.id.huogong
        };

        for (int id : buttonIds) {
            buttonStates.put(id, false);
        }
    }

    public void isPress(View view) {
        int buttonId = view.getId();
        if (Boolean.FALSE.equals(buttonStates.get(buttonId))) {
            view.setBackgroundResource(R.drawable.gray_button);
        } else {
            view.setBackgroundResource(R.drawable.sliver_button);
        }
        buttonStates.put(buttonId, Boolean.FALSE.equals(buttonStates.get(buttonId)));
    }

}
